package com.edu.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;


/**
 * @Author:zyn
 * @Date:2025/11/12--17:27:08
 */
public class MyAdvise {

    private Logger logger=LoggerFactory.getLogger(MyAdvise.class);

    public void logBeforeAdvise(JoinPoint jt){
        logger.debug(jt.getTarget()+":"+jt.getSignature().getName()+"()方法执行开始于："+new Date());
    }

    public Object logAroundAdvise(ProceedingJoinPoint pjt){
        Object result=null;
        try {
            Long start=System.currentTimeMillis();
            result=pjt.proceed();
            Thread.sleep(3000);
            Long end=System.currentTimeMillis();
            logger.debug(pjt.getTarget()+":"+pjt.getSignature().getName()+"()方法执行耗时："+(end-start));
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return result;
    }
}
